package com.squid.dataCenter.controller;

import com.squid.base.common.bean.PageReq;
import com.squid.base.common.bean.PageResp;
import com.squid.base.common.bean.Return;
import com.squid.dataCenter.model.req.datadictionary.DataDictionaryInsertReq;
import com.squid.dataCenter.model.req.datadictionary.DataDictionaryPageReq;
import com.squid.dataCenter.model.req.datadictionary.DataDictionaryUpdateReq;
import com.squid.dataCenter.model.resp.datadictionary.DataDictionaryPageResp;
import com.squid.dataCenter.service.datadictionary.DataDictionaryService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 数据字典控制器
 *
 * @author jinhang1
 * @date 2024/06/26
 */
@RestController
@RequestMapping("/dataDictionary")
public class DataDictionaryController {
    @Resource
    DataDictionaryService dataDictionaryService;

    @PostMapping("/page")
    public Return<PageResp<DataDictionaryPageResp>> page(@RequestBody PageReq<DataDictionaryPageReq> req) {
        PageResp<DataDictionaryPageResp> paging = dataDictionaryService.paging(req);
        return Return.<PageResp<DataDictionaryPageResp>>success().data(paging);
    }

    @PostMapping("/add")
    public Return<Object> add(@RequestBody DataDictionaryInsertReq req) {
        dataDictionaryService.add(req);
        return Return.success();
    }

    @PostMapping("/update")
    public Return<Object> update(@RequestBody DataDictionaryUpdateReq req) {
        dataDictionaryService.update(req);
        return Return.success();
    }

    @PostMapping("/delete")
    public Return<Object> delete(@RequestBody Long id) {
        dataDictionaryService.delete(id);
        return Return.success();
    }
}
